#coding=utf-8
import urllib2
#智库文档下载器
def code(strcode):
	temp = ''
	for i in strcode:
		temp = temp + hex(ord(i))[2:]
	return temp

#print code('1bd0995ad87df423dc763b3b122149c8|1530971557')


#请求头,模拟移动端访问,获取PDF文件
headers = {
	'Referer':'http://doc.mbalib.com/pdf/build/pdf.worker.js',
	'User-Agent':'Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Mobile Safari/537.36',
	'Host':'docread.mbalib.com',#站内访问
	'Origin':'http://doc.mbalib.com',
}
#PDF链接
url = 'http://docread.mbalib.com/pdf/6ce70deffabce24cdb4c52657207529d?code=31303162643935336531663536643734386631383639646338646531626564347c31353330393730303337'

#构建Request对象
req = urllib2.Request(url,headers = headers)
#请求Request对象
res = urllib2.urlopen(req)
#读取网页信息，数据为二进制数据
html = res.read()
#写入二进制数据到文件
with open('a.pdf','wb') as f:
	f.write(html)